# import the ucdp dataset and plot the figure -----------------------------

figure_1 <- read.csv("datasets/data_ucdp.csv") %>% 
  filter(country == "Turkey" & between(year, 2010, 2020) & 
           side_a == "Government of Turkey") %>% 
  mutate(date_start = as.Date(date_start),
         months = as.Date(cut(date_start, breaks = "month"))) %>% 
  group_by(months) %>% 
  summarise(casualties = sum(deaths_a)) %>% 
  ggplot(aes(x = months, y = casualties)) +
  geom_line(size = 1, stat = "identity") +
  geom_vline(xintercept = as.Date(c("2012-12-31", "2015-05-31", "2015-11-01")), 
             colour="gray60", linetype = "longdash") +
  geom_curve(aes(x = as.Date("2011-11-30"), 
                 y = 88, 
                 xend = as.Date("2012-11-30"), 
                 yend = 85),
             color = "gray60",
             arrow = arrow(length = unit(0.25,"cm"))) +
  geom_curve(aes(x = as.Date("2014-01-31"), 
                 y = 88, 
                 xend = as.Date("2015-03-31"), 
                 yend = 85),
             color = "gray60",
             arrow = arrow(length = unit(0.25,"cm"))) +
  geom_curve(aes(x = as.Date("2017-12-01"), 
                 y = 95, 
                 xend = as.Date("2015-12-15"), 
                 yend = 97),
             color = "gray60",
             arrow = arrow(length = unit(0.25,"cm"))) +
  annotate("text", x = as.Date("2011-11-30"), y = 93, 
           label = "Peace process\nstarts", colour = "gray60") +
  annotate("text", x = as.Date("2014-01-31"), y = 93, 
           label = "June 2015\nelection", colour = "gray60") +
  annotate("text", x = as.Date("2017-12-01"), y = 90, 
           label = "November 2015\nelection", colour = "gray60") +
  theme_light() +
  theme(axis.line = element_line(colour = "black", size = 0.25),
        panel.grid.major = element_line(colour = "grey95", size = 0.25),
        panel.grid.minor = element_line(colour = "grey95", size = 0.125),
        panel.border = element_rect(fill = NA, colour = "grey95", size = 0.25),
        axis.text = element_text(size = 12), 
        axis.title = element_text(size = 12)) +
  labs(x = NULL, y = "Monthly casualty total\n") +
  scale_x_date(breaks=c(as.Date("2010-01-01"), as.Date("2012-01-01"),
                        as.Date("2012-01-01"), as.Date("2014-01-01"), 
                        as.Date("2016-01-01"), as.Date("2018-01-01"),
                        as.Date("2020-01-01")), 
               date_labels = "%b \n %Y") +
  scale_y_continuous(limits = c(0, 105))

# display the figure ------------------------------------------------------

print(figure_1)

# save the figure ---------------------------------------------------------

ggsave(plot = figure_1, filename = "figures/figure_1.pdf", dpi = 1000, 
       width = 8.5, height = 6, units = "in")